home *** CD-ROM | disk | FTP | other *** search
- /*
- * $RCSfile: recoverUndoTrans.c,v $
- * $Revision: 1.2 $
- * $Date: 1996/05/04 23:51:54 $
- */
- /**********************************************************************
- * EXODUS Database Toolkit Software
- * Copyright (c) 1991 Computer Sciences Department, University of
- * Wisconsin -- Madison
- * All Rights Reserved.
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
- * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.
- * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
- * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * The EXODUS Project Group requests users of this software to return
- * any improvements or extensions that they make to:
- *
- * EXODUS Project Group
- * c/o David J. DeWitt and Michael J. Carey
- * Computer Sciences Department
- * University of Wisconsin -- Madison
- * Madison, WI 53706
- *
- * or exodus@cs.wisc.edu
- *
- * In addition, the EXODUS Project Group requests that users grant the
- * Computer Sciences Department rights to redistribute these changes.
- **********************************************************************/
-
- #include "sysdefs.h"
- #include "ess.h"
- #include "checking.h"
- #include "trace.h"
- #include "error.h"
- #include "list.h"
- #include "pool.h"
- #include "tid.h"
- #include "io.h"
- #include "lock.h"
- #include "object.h"
- #include "msgdefs.h"
- #include "thread.h"
- #include "semaphore.h"
- #include "latch.h"
- #include "link.h"
- #include "lsn.h"
- #include "bf.h"
- #include "log.h"
- #include "volume.h"
- #include "openlog.h"
- #include "trans.h"
- #include "logrecs.h"
- #include "log_intfuncs.h"
- #include "log_extfuncs.h"
- #include "lm_extfuncs.h"
- #include "trans_intfuncs.h"
- #include "trans_extfuncs.h"
- #include "recover_intfuncs.h"
- #include "thread_funcs.h"
- #include "thread_globals.h"
- #include "trans_globals.h"
- #include "recover_globals.h"
-
- #ifdef vax
- void
- recoverUndoTrans (
- register TRANSREC *transRec,
- )
-
- #else
- /* for all architectures but the vax */
- void
- recoverUndoTrans ()
- #endif
-
- {
- LIST pendingBitmapList;
-
- /*
- * This variable holds an argument passed the this function
- * when the thread was forked. This should be portable across
- * all architectures but vax's.
- */
- #if defined(vax)
- /* not needed */
- #else
- register TRANSREC *transRec;
- #endif
-
- TRACE(TR_TRANS, TR_LEVEL_1);
-
- /*
- * suck the transrec out of the tcb buffer
- */
- #ifdef mips
- SM_ASSERT(LEVEL_1, sizeof(transRec) == sizeof(Active->currentBuf[JB_A0]));
- transRec = (TRANSREC *) Active->currentBuf[JB_A0];
- #elif defined(sparc) || defined (_AIX) || defined(hpux) || defined(linux)
- /*
- * Sparc and other architectures
- */
- SM_ASSERT(LEVEL_1, sizeof(transRec) == sizeof(Active->args[0]));
- transRec = (TRANSREC *) Active->args[0];
- #elif defined(vax)
- /* not needed */
- #elif !(defined(mips) || defined(sparc) || defined(vax) || defined(_AIX) || defined(hpux) || defined(linux))
- not supported
- #else
- /* this else should have the not supported code, but the
- ultrix cpp is broken */
- #endif
-
- TRPRINT(TR_LOG|TR_RECOVER, TR_LEVEL_1, ("tid:%d", GETTID(transRec)));
-
- initializeList(&(pendingBitmapList));
-
- /*
- * Remember the transaction the thread is undoing
- */
- Active->transRec = (char *) transRec;
-
- /*
- * Free all information on files and pages
- * deallocated by this transaction
- */
- freeFileDeallocInfo(transRec);
- freePageDeallocInfo(transRec);
-
- undoTransaction(NULL_LSN, transRec->nextUndoLSN, LOG_RECOVERY);
-
- /*
- * check to see if there are any log records
- * that are written for this transaction
- */
- if (transRec->logRecordCount > 0) {
-
- /*
- * add all the pages in the all the files to be destroyed
- * to the list of pages to deallocate
- */
- if (transDeallocFilePages(transRec) != esmNOERROR) {
- /* clean up dealloc info */
- SM_ERROR(TYPE_CRASH, esmINTERNAL);
- }
-
- /*
- * Log all pending page deallocations
- */
- if (logTransDeallocPages(transRec, &pendingBitmapList) != esmNOERROR) {
- /*
- * For now, just crash, but we should really clean things up
- * and abort the transaction. Clean-up is complicated by
- * the bitmap and volume header pages which are pinned with
- * pending operations.
- */
- SM_ERROR(TYPE_CRASH, esmINTERNAL);
- }
-
- /*
- * we must log the final abort record, it need not be
- * forced to disk
- */
- if (writeTransStateRecord(transRec, LOG_REC_TYPE_ABORT, ZERO, T_ABORT, FALSE) < esmNOERROR) {
-
- SM_ERROR(TYPE_FATAL, Active->errno);
- }
-
- /*
- * Perform all pending page deallocations
- */
- if (deallocTransPages(transRec, &pendingBitmapList) != esmNOERROR) {
- SM_ERROR(TYPE_FATAL, esmINTERNAL);
- }
-
- /*
- * take the record off the log queue
- */
- removeLogList(transRec);
- }
-
- /*
- * Thread is no longer undoing a transaction
- */
- Active->transRec = NULL;
-
- /*
- * free all the locks
- */
- unlockAll(transRec, esmTRANSABORTED);
-
- /*
- * free the structures
- */
- freeTransVolRecs(transRec);
-
- /*
- * give back the transaction record
- */
- freeTransRec(transRec);
-
- /* thread is now done, so cleanup and wakeup any waiter */
- SM_ASSERT(LEVEL_3, UndoForkCount > 0);
- UndoForkCount--;
- notify(&RecoverUndoWaitList, esmNOERROR, esmNOERROR);
- threadRestart();
-
- return;
- }
-